// $(document).ready(function () {
/*
 * $('#add_plan').click(function () { //savePlan();
 * //document.planForm.submit(); });
 * 
 * $("#dialog").dialog("destroy"); $("#dialog-form").dialog({ autoOpen: false,
 * width: 460, modal: true, resizable: false, close: function() { $("#user-form
 * input").removeClass('invalid'); $("#user-form label").remove('.invalid');
 * getPaList(); } }); $('#addfeedbacksucc') .click(function() {
 * $('#dialog-form').dialog('open'); });
 */
// });
$(document).ready(function() {


	function getCurrentTime(){
	     var now= new Date();
         var year=now.getYear();
         var month=now.getMonth()+1;
         var day=now.getDate();
         var hour=now.getHours();
         var minute=now.getMinutes();
         var second=now.getSeconds();
         return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
	}
	
	$("#TfTime").attr("value",getCurrentTime());
	$("#TfTime").attr("disabled",true);
	
	// 上传窗口的
	$("#uploadFrame").dialog({
		autoOpen : false,
		width : 460,
		modal : true,
		resizable : false,
		close : function() {
			$("#upListDIV").empty();

			var myFileArr = window.frames["uploadFrame"].getFileArray();
			$.each(myFileArr, function(i, n) {
				var htmlStr = "";
				htmlStr += "<div><img src='lzm/images/doc.gif'/><span class='fn'>"
				htmlStr += n.originName;
				htmlStr += "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				htmlStr += "<span class='crtName' style='display:none;'>";
				htmlStr += n.crtName;
				htmlStr += "</span><a style='margin-left:10px;cursor:pointer;' class='dell'>删除</a></div>";
				$('#upListDIV').append(htmlStr);
			});
			$('.dell').unbind("click");
			$('.dell').click(function() {
						$(this).parent().remove();
					});
			$("#upListDIV").show();

		}
	});

	// “上传附件”按钮的响应
	$("#upFile").click(function() {
				$("#uploadFrame").dialog("open");
			});

	// var cookie = $.cookie('taskmsg');
	// if (cookie != null) {
	// var msg = cookie.split("+");
	// // alert(msg);
	// $.each(msg, function(i, n) {
	// switch (i) {
	// case 0 :
	// $("#Tid").val(n);
	// break;
	// case 1 :
	// $("#TfPeople").val(n);
	// break;
	// default :
	// break;
	// }
	// });
	// }

	// 收集请求参数
	function getParams() {
		var tid = $.trim($("#Tid").val());
		var tfPeople = $.trim($("#TfPeople").val());
		var tfTime = $.trim($("#TfTime").val());
		var tfText = $.trim($("#TfText").val());
		var tfNote = $.trim($("#TfNote").val());

		var filename = new Array();
		var fileid = new Array();
		$("#upListDIV > *").each(function(i, n) {
					var p = $(this).find(".fn").text();
					filename.push($.trim(p));

					var pp = $(this).find(".crtName").text();
					fileid.push($.trim(pp));

				});

		params = {
			"queryOption['tid']" : tid,
			"queryOption['tfPeople']" : tfPeople,
			"queryOption['tfTime']" : tfTime,
			"queryOption['tfText']" : tfText,
			"queryOption['tfNote']" : tfNote,
			"queryOption['tfannex']" : filename.toString(),
			"queryOption['tfannexid']" : fileid.toString()
		};
		return params;
	}

	$("#submit").click(function() {
				if ( $("#TfText").val() == "") {
					alert("请填写必要信息!");
					return false;
				} else {
					$.ajax({
								type : "post",
								url : "/ag/lzw/handelFeedback_saveFeedback.action",
								data : getParams(),
								dataType : "JSON",
								success : addSucc,
								error : function(textStatus) {
									alert("Ajax请求失败，请检查本地的网络连接！");
									return false;
								}
							});
				}
			});

	function addSucc(data) {
        var d = eval("(" + data + ")");
		if (d.ajaxString == 0) {
			alert("添加任务反馈成功");
		    $('#taskTrackFrame', window.parent.document).attr("src","/ag/lzw/tracklist_trackdetail_main.jsp");
		}

	}
	

});
